<?php

namespace addons\shop\controller\api;

use addons\shop\model\Exchange;
use addons\shop\model\ExchangeOrder;
use addons\shop\model\ScoreLog;
use app\admin\model\user\money\Log as UserMoneyLog;
use addons\shop\model\Address;
use think\Db;

/**
 * 返利积分日志接口
 */
class Jifen extends Base
{
    protected $noNeedLogin = ['exchangeList'];

    /**
     * 积分日志
     */
    public function logs()
    {
        $type = $this->request->param('type');
        $type2 = $this->request->param('type2');
        $page = $this->request->param('page', 1); // 获取页码参数，默认为1
        
        $where = ['user_id' => $this->auth->id];
        
        // 如果传入了type2参数，只查询type2条件
        if (!empty($type2)) {
            $where['type2'] = $type2;
        } elseif (!empty($type)) {
            // 如果没有type2参数但有type参数，添加type条件
            $where['type'] = $type;
        }
        
        if ($page>1) {
            $this->error('只展示最近10条记录');
        }
        
        $list = UserMoneyLog::where($where)
            ->order('id desc')
            ->paginate(10, false, ['page' => $page]);

        $this->success('', $list);
    }

}